package com.central.user.service.impl;

import com.central.model.common.PageResult;
import com.central.model.common.utils.PageUtil;
import com.central.user.dao.BsdldDao;
import com.central.user.model.FightInfo;
import com.central.user.model.PlayerBagInfo;
import com.central.user.model.PlayerDetailsInfo;
import com.central.user.service.BsdldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@Service
public class BsdldServiceImpl implements BsdldService {

    @Autowired
    private BsdldDao bsdldDao;

    @Override
    public PageResult<FightInfo> findFightInfoAll(Map<String, Object> params) {
        int total = bsdldDao.countFightInfo();
        List<FightInfo> list = Collections.emptyList();
        for (Object obj: params.values()){
            System.out.println(obj);
        }
//        total = 2;
        if (total > 0) {
            PageUtil.pageParamConver(params, true);
            list = bsdldDao.findFightInfoAll(params);
        }
        return PageResult.<FightInfo>builder().data(list).code(0).count((long)total).build();
    }

    @Override
    public PlayerDetailsInfo findByPlayerId(String playerId) {
        List<PlayerDetailsInfo> baseInfos = bsdldDao.findByPlayerId(playerId);
        if (baseInfos.size() == 1){
            return baseInfos.get(0);
        }
        return null;
    }

    @Override
    public PlayerBagInfo findBagByPlayerId(String playerId) {
        List<PlayerBagInfo> bagInfos =  bsdldDao.findBagInfo(playerId);
        if (bagInfos.size() == 1){
            return bagInfos.get(0);
        }
        return null;
    }
}
